package com.android.home.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.common.base.rv.BaseRvAdapter;
import com.android.common.base.rv.BaseRvHolder;
import com.android.home.R;
import com.android.home.mvp.model.home.GroupBean;

public abstract class GroupTitleHolder extends BaseRvHolder<GroupBean.ItemsBean>
    implements View.OnClickListener {

    private Context mContext;

    private TextView mTvTitle;

    private RecyclerView mRvGroupContent;

    private BaseRvAdapter<GroupBean.ItemsBean.ResultBean> mAdapter;


    public GroupTitleHolder(View itemView) {
        super(itemView);
        mContext = itemView.getContext();
        mTvTitle = itemView.findViewById(R.id.tv_title);
        mRvGroupContent = itemView.findViewById(R.id.rv_group_content);
        mRvGroupContent.setLayoutManager(new LinearLayoutManager(mContext));
        mAdapter = initAdapter(this);
    }

    @Override
    public void bindData(GroupBean.ItemsBean bean, int position) {
        mTvTitle.setText(bean.getTitle());
        mAdapter.setDataAndNotify(bean.getResult());
        mRvGroupContent.setAdapter(mAdapter);
    }

    @Override
    public void onClick(View view) {
        if (mChildViewClickListener != null) {
            mChildViewClickListener.onChildViewClick(view, getBindingAdapterPosition());
        }
    }

    protected abstract BaseRvAdapter<GroupBean.ItemsBean.ResultBean> initAdapter(GroupTitleHolder holder);
}
